<?php

namespace app\admin\controller;

use think\facade\Db;
use think\facade\View;
use think\Request;

class Iframe extends Base
{
    /**
     * 所有会员 -- 多选
     */
    public function checkboxUserList(Request $request)
    {
        $param = $request->param();

        if ($request->isAjax()) {
            $model = new \app\common\model\User();

            // 每页起始条数
            $start = ($param['page'] - 1) * $param['limit'];
            // 每页显示条数
            $length = $param['limit'];
            // 排序条件
            $order = '';

            $where = $this->getFilterWhere($request);
            if ($this->defaultWhere) {
                $where = array_merge($this->defaultWhere, $where);
            }
            if ($this->defaultOrder) {
                $order = $this->defaultOrder;
            }

            $data = $model->where($where)->order($order)->limit($start, $length)->select();
            $count = $model->where($where)->count();
            if ($data) {
                // 处理列表数据
                $data = $this->handleListData($data);
            }

            $result = [
                'code' => '0',
                'msg' => '',
                'data' => $data,
                'count' => $count,
            ];

            return json($result);
        }

        return view('iframe/checkbox_user_list', [
            'params' => $request->param()
        ]);
    }

    /**
     * 选择文件
     */
    public function selectFiles(Request $request)
    {
        $param = $request->param();

        if ($request->isAjax()) {
            $model = new \app\common\model\File();

            // 每页起始条数
            $start = ($param['page'] - 1) * $param['limit'];
            // 每页显示条数
            $length = $param['limit'];
            // 排序条件
            $order = '';

            $where = $this->getFilterWhere($request);
            if ($this->defaultWhere) {
                $where = array_merge($this->defaultWhere, $where);
            }
            if ($this->defaultOrder) {
                $order = $this->defaultOrder;
            }

            $data = $model->where($where)->order($order)->limit($start, $length)->select();
            $count = $model->where($where)->count();
            if ($data) {
                // 处理列表数据
                $data = $model->formatDatas($data);
            } else {
                return json([
                    'code' => 0,
                ]);
            }

            return json([
                'code' => 1,
                //'datas' => $data,
                'count' => $count,
                'html' => View::fetch('iframe/ajax_files', [
                    'datas' => $data,
                    'count' => $count
                ])
            ]);
        }

        return view('iframe/select_files', [
            'params' => $request->param()
        ]);
    }

    /**
     * Icon 图标
     */
    public function icons(Request $request)
    {
        $datas = config('icons');

        return view('iframe/icons', [
            'datas' => $datas
        ]);
    }

    /**
     * Map 地图
     */
    public function map(Request $request)
    {
        return view('iframe/map');
    }
}
